﻿@{
    ViewBag.Title = "查询 RPC 服务依赖配置";
}
@using YmtRpc.Domain;
@model List<SeviceConfig>

<form role="form">
    <div class="form-group">

        <label for="name">依赖关系</label>
        <select class="form-control" id="dependencyRelation" name="dependencyRelation" style="width:500px" onchange="UpdateAppIdList()">
            
            @foreach (var kv in ViewBag.dependencyRelationDict)
            {
                if (string.Equals(kv.Key, ViewBag.dependencyRelation))
                {
                    <option value="@kv.Key" selected="selected">@kv.Value</option>
                }
                else
                {
                    <option value="@kv.Key">@kv.Value</option>
                }
            }
        </select>

        <label for="name" id="name">名称</label>

        <select class="form-control" style="width:500px" id="appid" name="appid">

            @foreach (string app in ViewBag.AppList)
            {
                if (string.Equals(app, ViewBag.AppId))
                {
                    <option value="@app" selected="selected">@app</option>
                }
                else
                {
                    <option value="@app">@app</option>
                }
            }
        </select>

        <button type="submit" class="btn btn-default" style="margin-left:20px;" onclick="query(); return false;">查询</button>
    </div>
</form>

<table class="table table-striped table-bordered table-hover">
    <thead>
        <tr>
            <th style="width:50px">序号</th>
            <th>服务消费者应用编号</th>
            <th>服务提供者应用编号</th>
            <th>是否启用访问权限</th>
            <th>创建时间</th>
            <th>上次更新时间</th>
        </tr>
    </thead>
    <tbody id="samplingDataContent">
        @if (Model != null)
        {
            int i = 1;
            foreach (SeviceConfig entity in Model)
            {
                <tr>
                    <td>@(i++)</td>
                    <td>@entity.ConsumerAppId</td>
                    <td>@entity.ProviderAppId</td>
                    <td>@entity.IsDisabled</td>
                    <td>@entity.CreateTime</td>
                    <td>@entity.LastUpdateTime</td>
                </tr>
            }
        }
    </tbody>
</table>

<script type="text/javascript">
    
    function UpdateAppIdList() {
        $("#appid").empty();
        $.ajax({
            type: "GET",
            url: "/Config/GetAppListFromServiceConfig?dependencyRelation=" + $("#dependencyRelation")[0].value,
            dataType: "json",
            success: function (data) {

                $.each(data, function (n, e) {
                    $("#appid").append("<option value=\"" + e + "\">" + e + "</option>");
                });
            }
        });
    }

    function query() {

        var href = "/Config/ServiceConfig";
        var dependencyRelation = $("#dependencyRelation")[0].value
        var appId = $("#appid")[0].value;

        if (app != "") {
            href = href + "?dependencyRelation=" + dependencyRelation + "&appId=" + appId;
        }

        location.href = href;
        return false;
    }

    $(document).ready(function () {
        var url = location.href;
        var paraString = url.substring(url.indexOf("?") + 1, url.length).split("&");

        var paraObj = {};
        for (i = 0; j = paraString[i]; i++) {
            var key = j.substring(0, j.indexOf("="));

            if (key.length == 0)
                continue;

            paraObj[key] = j.substring(j.indexOf("=") + 1, j.length);
        }

        if (paraObj['dependencyRelation'] == undefined)
            UpdateAppIdList();
    });
</script>







